package com.goods.service.imp;

import com.goods.business.mapper.SupplierMapper;
import com.goods.common.model.business.Supplier;
import com.goods.common.utils.ListPageUtils;
import com.goods.common.vo.system.PageVO;
import com.goods.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class SupplierServiceImpl implements SupplierService {

    @Autowired
    private SupplierMapper supplierMapper;
   /* @Override
    public PageVO findSupplierList(Map map) {

        return null;
    }*/

    @Override
    public PageVO findSupplierList(Integer pageNum, Integer pageSize) {
        List<Supplier> suppliers = supplierMapper.selectAll();
        if (null != suppliers) {
            List<Supplier> page = ListPageUtils.page(suppliers, pageSize, pageNum);
            return new PageVO<>(suppliers.size(), page);
        }
        return null;
    }

    @Override
    public void add(Supplier supplier) {
        if (null != supplier) {
            supplier.setCreateTime(new Date());
            supplier.setModifiedTime(new Date());
            supplierMapper.insert(supplier);
        }
    }

    @Override
    public Supplier edit(Long id) {
        return supplierMapper.selectByPrimaryKey(id);
    }

    @Override
    public void update(Long id, Supplier supplier) {
        if (null != supplier) {
            supplier.setId(id);
            supplier.setModifiedTime(new Date());
            supplierMapper.updateByPrimaryKey(supplier);
        }
    }

    @Override
    public void delete(Long id) {
        supplierMapper.deleteByPrimaryKey(id);
    }
}
